package com.neshai.webapp.service;

import com.neshai.webapp.entity.User;
import com.neshai.webapp.mapper.UserMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class UsageService {


    private final UserMapper userMapper;

    public boolean useBasicService(int userId) {
        User user = userMapper.selectById(userId);
        if (user == null) {
            return false;
        } else {
            switch (user.getVipLevel()) {
                case 0:
                    if (user.getUsageBasic() >= 20) {
                        return false;
                    }
                    break;
                case 1:
                    if (user.getUsageBasic() >= 10000) {
                        return false;
                    }
                    break;
                case 2:
                    break;
            }
            int i = userMapper.incrementUsageBasicById(userId);
            return i == 1;
        }
    }

    public boolean usePremiumService(int userId) {
        User user = userMapper.selectById(userId);
        if (user == null) {
            return false;
        } else {
            switch (user.getVipLevel()) {
                case 0:
                    if (user.getUsagePremium() >= 6) {
                        return false;
                    }
                    break;
                case 1:
                    if (user.getUsagePremium() >= 1500) {
                        return false;
                    }
                    break;
                case 2:
                    break;
            }
            int i = userMapper.incrementUsagePremiumById(userId);
            return i == 1;
        }
    }
}
